<?php
/**
 * File: RequestParam.php.
 * User: Yan<me@xiaoyan.me>
 * DateTime: 2017-12-19 21:51
 */

namespace App\Core;


class RequestParam
{
    private $params;
    public $raw;

    public function __construct(&$data)
    {
        $this->params = &$data;
    }

    public function getInt($key)
    {
        return (int)$this->get($key);
    }

    public function get($key, $default = null)
    {
        return isset($this->params[$key]) ? $this->params[$key] : $default;
    }

    /**
     * @param $key
     * @param $value
     * @return RequestParam
     */
    public function put($key, $value)
    {
        $this->params[$key] = $value;

        return $this;
    }

    public function raw()
    {
        return http_build_query($this->params);
    }

    public function getAll()
    {
        return $this->params;
    }
}